package com.medical.smartcare.asynctask;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.util.Log;

public class WebApiAsyncTask extends AsyncTask<String, Integer, JSONObject>
{
	private static final String TAG = WebApiAsyncTask.class.getSimpleName();

	public static String url_Register = "http://kaivor.noip.me/medical_app/v1/register";
	public static String url_Login = "http://kaivor.noip.me/medical_app/v1/login";
	public static String url_ViewInfo = "http://kaivor.noip.me/medical_app/v1/viewinfo";
	public static String url_UpdateName = "http://kaivor.noip.me/medical_app/v1/updatename";
	public static String url_DeleteCP = "http://kaivor.noip.me/medical_app/v1/deletecp";

	@Override
	protected JSONObject doInBackground(String... params)
	{
		JSONObject jsonObject = null;
		try
		{
			HttpPost httpPost = new HttpPost(params[0]);
			StringEntity se = new StringEntity(params[1]);
			httpPost.setEntity(se);
			httpPost.setHeader("Accept", "application/json");
			httpPost.setHeader("Content-type", "application/json");
			HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost);

			String retSrc = EntityUtils.toString(httpResponse.getEntity());
			jsonObject = new JSONObject(retSrc);
		}
		catch (Exception ex)
		{
			Log.e(TAG, ex.toString());
			jsonObject = null;
		}
		return jsonObject;
	}
}
